package com.burgeon.backend.SHOP.controller;

import com.burgeon.backend.SHOP.service.ShareService;
import com.burgeon.backend.stsutil.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.HashMap;

@RestController
@CrossOrigin
@RequestMapping("shop/share")
public class ShareController extends BaseController {
    @Autowired
    private ShareService shareService;

    /**分享*/
    @RequestMapping("insert")
    public ResponseResult<Void> insertShare(HttpSession session) {
        if (session.getAttribute("uid")==null){
            return new ResponseResult<>(NOTLOG);
        }
        String uid = session.getAttribute("uid").toString();
        String token = session.getAttribute("token").toString();
        String phone = session.getAttribute("phone").toString();
        shareService.insertShare(token,phone,uid);

        return new ResponseResult<>(SUCCESS);
    }

    /**分享状态，是否分享*/
    @RequestMapping("findShare")
    public ResponseResult<HashMap> findShare(HttpSession session) {
        String uid = session.getAttribute("uid").toString();
        String token = session.getAttribute("token").toString();
        HashMap data =shareService.getShareByTime(token,uid);
        return new ResponseResult<HashMap>(SUCCESS,data);
    }

}
